package com.cdks.wuxiu.api.service;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.cdks.wuxiu.api.service.mysql.UserAlbumInfoService;
import com.cdks.wuxiu.api.util.TimeUtils;
import com.cdks.wuxiu.entity.mysql.UserAlbumInfo;


@Slf4j
@Service
public class AlbumServiceImpl implements AlbumService {
    @Resource
    private UserAlbumInfoService userAlbumInfoService; 
    
    
    @Override
    public int saveImage(long userId, String imageUri, int type, int status) {
        try {
            UserAlbumInfo album  = new UserAlbumInfo();
            album.setCreateTime(TimeUtils.getTimeSecond());
            album.setImageUri(imageUri);
            album.setType(type);
            album.setUserId(userId);
            album.setStatus(status);

            userAlbumInfoService.save(album);
        } catch (Exception e) {
            if (e instanceof DuplicateKeyException) {
                return -1;
            }
        }

        return 0;
    }

    @Override
    public int findImage(long userId, String imageUri) {
        userAlbumInfoService.findByName(userId, imageUri);

        return 0;
    }

    @Override
    public int deleteImage(long userId, String imageUri) {
        userAlbumInfoService.deleteByName(userId, imageUri);

        return 0;
    }

    @Override
    public List<UserAlbumInfo> getPhotosByUser(long destId, Integer page) {
        return userAlbumInfoService.getPhotosByUser(destId, page);
    }
}
